total_issuance_all       =   total_issuance_all*1000,
#
#
total_redemptions_bills  =   total_redemptions_bills*1000,
total_redemptions_bonds  =   total_redemptions_bonds*1000,
total_redemptions_notes  =   total_redemptions_notes*1000,
coupon_redemptions       =   coupon_redemptions*1000,
#
#
Bond_position            =   Bond_position*1000,
Note_position            =   Note_position*1000,
TIP_position             =   TIP_position*1000,
AGYMBS_position          =   AGYMBS_position*1000,
NetPosition_all          =   NetPosition_all*1000,
Corporation_Income_Taxes_trillion = Corporation_Income_Taxes_trillion*1000,
top100balance1 = top100balance1*1000,
DlrDepUnins = DlrDepUnins * 1000
)
data2worktem1 = data2worktem %>%
select(Date,
Repo_balances1  ,
AO_balances1  ,
top100balance1,
# agg_balance_drop1  ,
#
Tbills_outstanding  ,
#
total_issuance_bills  ,
coupon_issuances  ,
TBills_position  ,
total_redemptions_all  ,
NetPosition_try  ,
tdiff50_recv1,
tdiff50_send1,
tdiff25_newIV,
tdiff50_newIV  ,
tdiff75_newIV    ,
SOFR_IOER,
# GCF_IOER,
# TGCR_IOER,
total_issuance_all,
QuarterEnd ,
Corporation_Income_Taxes_trillion,
DlrDepUnins,
logSOFR_IOER_normalized
) %>% mutate(#Ave_tdiff50_recv1_3 = zoo::rollmean(tdiff50_recv1, k = 3, align = "right", fill = NA, na.rm = TRUE),
# Ave_tdiff50_recv1_5 = zoo::rollmean(tdiff50_recv1, k = 5, align = "right", fill = NA, na.rm = TRUE),
# Ave_tdiff50_recv1_7 = zoo::rollmean(tdiff50_recv1, k = 7, align = "right", fill = NA, na.rm = TRUE),
Ave_tdiff50_recv1_9 = zoo::rollmean(tdiff50_recv1, k = 9, align = "right", fill = NA, na.rm = TRUE),
# Ave_tdiff50_recv1_11 = zoo::rollmean(tdiff50_recv1, k = 11, align = "right", fill = NA, na.rm = TRUE),
# Ave_tdiff50_recv1_13 = zoo::rollmean(tdiff50_recv1, k = 13, align = "right", fill = NA, na.rm = TRUE),
# Ave_tdiff50_recv1_15 = zoo::rollmean(tdiff50_recv1, k = 15, align = "right", fill = NA, na.rm = TRUE),
# Ave_tdiff50_recv1_17 = zoo::rollmean(tdiff50_recv1, k = 17, align = "right", fill = NA, na.rm = TRUE),
# Ave_tdiff50_recv1_19 = zoo::rollmean(tdiff50_recv1, k = 19, align = "right", fill = NA, na.rm = TRUE),
# Ave_tdiff50_recv1_21 = zoo::rollmean(tdiff50_recv1, k = 21, align = "right", fill = NA, na.rm = TRUE),
# AveBalancesPreviousWeeklag3 = lag(Ave_tdiff50_recv1_3, 2),
# AveBalancesPreviousWeeklag5 = lag(Ave_tdiff50_recv1_5, 2),
# AveBalancesPreviousWeeklag7 = lag(Ave_tdiff50_recv1_7, 2),
AveBalancesPreviousWeeklag9 = lag(Ave_tdiff50_recv1_9, 2)
# AveBalancesPreviousWeeklag11 = lag(Ave_tdiff50_recv1_11, 2),
# AveBalancesPreviousWeeklag13 = lag(Ave_tdiff50_recv1_13, 2),
# AveBalancesPreviousWeeklag15 = lag(Ave_tdiff50_recv1_15, 2),
# AveBalancesPreviousWeeklag17 = lag(Ave_tdiff50_recv1_17, 2),
# AveBalancesPreviousWeeklag19 = lag(Ave_tdiff50_recv1_19, 2),
# AveBalancesPreviousWeeklag21 = lag(Ave_tdiff50_recv1_21, 2),
# lag2_Repo_balances1 = lag(Repo_balances1, 2)
)
data2worktem1 =
apply_labels(
data2worktem1,
Repo_balances1	=	paste0(		var_lab(data2worktem1$Repo_balances1)		, "	($ billions)"	),
AO_balances1	=	paste0(		var_lab(data2worktem1$AO_balances1)		, "	($ billions)"	),
top100balance1	=	paste0(		var_lab(data2worktem1$top100balance1)		, "	($ billions)"	),
Tbills_outstanding	=	paste0(		var_lab(data2worktem1$Tbills_outstanding)		, "	($ billions)"	),
#	=	paste0(		var_lab(data2worktem1$#)		, "	($ billions)"	),
total_issuance_bills	=	paste0(		var_lab(data2worktem1$total_issuance_bills)		, "	($ billions)"	),
coupon_issuances	=	paste0(		var_lab(data2worktem1$coupon_issuances)		, "	($ billions)"	),
TBills_position	=	paste0(		var_lab(data2worktem1$TBills_position)		, "	($ billions)"	),
total_redemptions_all	=	paste0(		var_lab(data2worktem1$total_redemptions_all)		, "	($ billions)"	),
NetPosition_try	=	paste0(		var_lab(data2worktem1$NetPosition_try)		, "	($ billions)"	),
tdiff50_recv1	=	paste0(		var_lab(data2worktem1$tdiff50_recv1)		, "	(minutes)"	),
tdiff50_send1	=	paste0(		var_lab(data2worktem1$tdiff50_send1)		, "	(minutes)"	),
#
tdiff25_newIV	=	paste0(		var_lab(data2worktem1$tdiff25_newIV)		, "	(minutes)"	),
tdiff50_newIV	=	paste0(		var_lab(data2worktem1$tdiff50_newIV)		, "	(minutes)"	),
tdiff75_newIV	=	paste0(		var_lab(data2worktem1$tdiff75_newIV)		, "	(minutes)"	),
#
SOFR_IOER	=	paste0(		var_lab(data2worktem1$SOFR_IOER)		, "	(basis points)"	),
# GCF_IOER	=	paste0(		var_lab(data2worktem1$GCF_IOER)		, "	(basis points)"	),
#TGCR_IOER	=	paste0(		var_lab(data2worktem1$#TGCR_IOER)		, "	(basis points)"	),
total_issuance_all	=	paste0(		var_lab(data2worktem1$total_issuance_all)		, "	($ billions)"	),
QuarterEnd	=	paste0(		var_lab(data2worktem1$QuarterEnd)		, "	"	),
Corporation_Income_Taxes_trillion	=	paste0(		var_lab(data2worktem1$Corporation_Income_Taxes_trillion)		, "	($ billions)"	),
DlrDepUnins	=	paste0(		var_lab(data2worktem1$DlrDepUnins)		, "	($ billions)"	),
logSOFR_IOER_normalized	=	paste0(		var_lab(data2worktem1$logSOFR_IOER_normalized)		, "	"	),
AveBalancesPreviousWeeklag9 = "Average Payment Delay t-10 to t-2"
)
data2work7 = names2labels(data2worktem1)
data2work7 %<>% select(-Date)
res = remove_backticks(
stargazer(data2work7,
digits = 1, summary.stat = c("n",	"mean",	"sd",	"min",	"p25",	"median",	"p75",	"max"                )
))
res[grepl("\\label\\{\\}",res)] = "%"
res[grepl("\\caption\\{",res)] = "%"
res[grepl("Table created by stargazer v.5.2.2 by Marek Hlavac",res)] = ""
res[grepl("\\% Date and time:",res)] = ""
res[grepl("\\% Requires LaTeX packages: dcolumn",res)] = ""
#
res[grepl("begin\\{table\\}",res)] = begintable.latex
res[grepl("end\\{table\\}",res)] = endtable.latex
cat("\014")
write_clip(res)
writeLines(res)
cat("\014")
# **********************************************************
rm( list = setdiff( ls(), c(keepVariables, "data2worktem") ))
data2worktem1 = data2worktem %>%
select(#SOFR	,
# TGCR	,
# GCF	,
IOER	,
# BGCR	,
TGCR_IOER	,
GCF_IOER	,
# BGCR_IOER	,
total_issuance_bonds	,
total_issuance_notes	,
total_redemptions_bills	,
total_redemptions_bonds	,
total_redemptions_notes	,
# coupon_redemptions	,
# Bond_position	,
# Note_position	,
# TIP_position	,
# AGYMBS_position	,
NetPosition_all	,
# BeforeQE	,
# AfterQE	,
# agg_balance_drop1	,
# tdiff50_recvF1	,
# tdiff25_recvF1	,
# tdiff75_recvF1	,
tdiff50_all1	,
tdiff25_all1	,
tdiff75_all1	,
tdiff25_send1	,
tdiff75_send1	,
tdiff25_recv1	,
tdiff75_recv1
)
data2worktem1 =
apply_labels(
data2worktem1,
# SOFR	=	paste0(		var_lab(data2worktem1$SOFR)		, "SOFR	(basis points)"	),
# TGCR	=	paste0(		var_lab(data2worktem1$# TGCR)		, "	(basis points)"	),
# GCF	=	paste0(		var_lab(data2worktem1$# GCF)		, "	(basis points)"	),
IOER	=	paste0(		var_lab(data2worktem1$IOER)		, "IOR	(basis points)"	),
# BGCR	=	paste0(		var_lab(data2worktem1$# BGCR)		, "	(basis points)"	),
TGCR_IOER	=	paste0(		var_lab(data2worktem1$TGCR_IOER)		, "	(basis points)"	),
GCF_IOER	=	paste0(		var_lab(data2worktem1$GCF_IOER)		, "	(basis points)"	),
# BGCR_IOER	=	paste0(		var_lab(data2worktem1$# BGCR_IOER)		, "	(basis points)"	),
total_issuance_bonds	=	paste0(		var_lab(data2worktem1$total_issuance_bonds)		, "	($ billions)"	),
total_issuance_notes	=	paste0(		var_lab(data2worktem1$total_issuance_notes)		, "	($ billions)"	),
total_redemptions_bills	=	paste0(		var_lab(data2worktem1$total_redemptions_bills)		, "	($ billions)"	),
total_redemptions_bonds	=	paste0(		var_lab(data2worktem1$total_redemptions_bonds)		, "	($ billions)"	),
total_redemptions_notes	=	paste0(		var_lab(data2worktem1$total_redemptions_notes)		, "	($ billions)"	),
# coupon_redemptions	=	paste0(		var_lab(data2worktem1$coupon_redemptions)		, "	($ billions)"	),
# Bond_position	=	paste0(		var_lab(data2worktem1$# Bond_position)		, "	($ billions)"	),
# Note_position	=	paste0(		var_lab(data2worktem1$# Note_position)		, "	($ billions)"	),
# TIP_position	=	paste0(		var_lab(data2worktem1$# TIP_position)		, "	($ billions)"	),
# AGYMBS_position	=	paste0(		var_lab(data2worktem1$# AGYMBS_position)		, "	($ billions)"	),
NetPosition_all	=	paste0(		var_lab(data2worktem1$NetPosition_all)		, "	($ billions)"	),
# BeforeQE	=	paste0(		var_lab(data2worktem1$# BeforeQE)		, "	"	),
# AfterQE	=	paste0(		var_lab(data2worktem1$# AfterQE)		, "	"	),
# agg_balance_drop1	=	paste0(		var_lab(data2worktem1$# agg_balance_drop1)		, "	($ billions)"	),
# tdiff50_recvF1	=	paste0(		var_lab(data2worktem1$# tdiff50_recvF1)		, "	"	),
# tdiff25_recvF1	=	paste0(		var_lab(data2worktem1$# tdiff25_recvF1)		, "	(minutes)"	),
# tdiff75_recvF1	=	paste0(		var_lab(data2worktem1$# tdiff75_recvF1)		, "	(minutes)"	),
tdiff50_all1	=	paste0(		var_lab(data2worktem1$tdiff50_all1)		, "	(minutes)"	),
tdiff25_all1	=	paste0(		var_lab(data2worktem1$tdiff25_all1)		, "	(minutes)"	),
tdiff75_all1	=	paste0(		var_lab(data2worktem1$tdiff75_all1)		, "	(minutes)"	),
tdiff25_send1	=	paste0(		var_lab(data2worktem1$tdiff25_send1)		, "	(minutes)"	),
tdiff75_send1	=	paste0(		var_lab(data2worktem1$tdiff75_send1)		, "	(minutes)"	),
tdiff25_recv1	=	paste0(		var_lab(data2worktem1$tdiff25_recv1)		, "	(minutes)"	),
tdiff75_recv1	=	paste0(		var_lab(data2worktem1$tdiff75_recv1)		, "	(minutes)"	)
)
data2work7 = names2labels(data2worktem1)
res = remove_backticks(
stargazer(data2work7,
digits = 1
))
# -----------------Probit Regression -----------------------------------------
# Table 10 and Table 11
rm( list = setdiff( ls(), c(keepVariables, "") ))
cat("\014")
tem1 = zoo::na.locf(data2work1, na.rm = FALSE)
tem2 = tem1 %>%
mutate(SOFR_IOER2 = SOFR_IOER,
GCF_IOER2 = GCF_IOER,
TGCR_IOER2 = TGCR_IOER,
SOFR_IOER = pmin(SOFR_IOER, 30),
GCF_IOER  = pmin(GCF_IOER,  30),
TGCR_IOER = pmin(TGCR_IOER, 30)
) %>%
mutate(smooth_SOFR_IOER =  zoo::rollmean( lag(SOFR_IOER), 15, fill=NA, align="right"),
smooth_GCF_IOER  =  zoo::rollmean( lag(GCF_IOER), 15, fill=NA, align="right"),
smooth_TGCR_IOER =  zoo::rollmean( lag(TGCR_IOER), 15, fill=NA, align="right"),
dif_SOFR_IOER = SOFR_IOER2 - smooth_SOFR_IOER,
dif_GCF_IOER  = GCF_IOER2  - smooth_GCF_IOER ,
dif_TGCR_IOER = TGCR_IOER2 - smooth_TGCR_IOER) %>%
select(Date, smooth_SOFR_IOER, smooth_GCF_IOER, smooth_TGCR_IOER, dif_SOFR_IOER, dif_GCF_IOER, dif_TGCR_IOER)
data2work = data2work1 %>%
left_join(tem2, by = 'Date') %>%
mutate(critical_flag1 = ifelse( (dif_SOFR_IOER >= 15 | dif_GCF_IOER >= 15 | dif_TGCR_IOER >= 15 | SOFR_IOER >=20 | GCF_IOER >= 30 | TGCR_IOER >= 20) & !is.na(SOFR_IOER), 1, 0)  ) %>%
mutate(critical_flag = ifelse(is.na(critical_flag1), 0, critical_flag1) ) %>% select(-critical_flag1)
# mutate(critical_flag = if_else( (SOFR_IOER >25 | GCF_IOER >25 ), 1, 0 ))
cat("\014")
# colnames(data2worktem1)
data2worktem1 = data2work %>% filter(critical_flag==1) %>%
select(Date,
SOFR_IOER,
GCF_IOER,
TGCR_IOER,
Repo_balances1,
AO_balances1,
total_issuance_all,
total_redemptions_all
) %>%
# Change units to billion dollars
mutate(Repo_balances1	=	Repo_balances1	*	1000	,
AO_balances1	=	AO_balances1	*	1000	,
total_issuance_all	=	total_issuance_all	*	1000	,
total_redemptions_all	=	total_redemptions_all	*	1000	)
# Table 10
data2work7.2 = names2labels(data2worktem1)
res = remove_backticks(
stargazer(data2work7.2, summary = FALSE,
digits = 2))
res[grepl("\\label\\{\\}",res)] = "%"
res[grepl("\\caption\\{",res)] = "%"
res[grepl("Table created by stargazer v.5.2.2 by Marek Hlavac",res)] = ""
res[grepl("\\% Date and time:",res)] = ""
res[grepl("\\% Requires LaTeX packages: dcolumn",res)] = ""
#
res[grepl("begin\\{table\\}",res)] = begintable.latex
res[grepl("end\\{table\\}",res)] = endtable.latex
cat("\014")
write_clip(res)
writeLines(res)
cat("\014")
# Table 11
regressor_list = c(
'tdiff50_recv1', 'Repo_balances1',
'tdiff50_recv1 + Repo_balances1',    'coupon_issuances',
'tdiff50_recv1 + coupon_issuances',
'tdiff50_recv1 + Repo_balances1 + coupon_issuances',
'tdiff50_recv1 + Repo_balances1 + coupon_issuances + QuarterEnd'
)
dep_list = c('critical_flag')
reg_list = vector(mode = 'list', length = length(regressor_list) * length(dep_list) )
robust_se = vector(mode = 'list', length = length(regressor_list) * length(dep_list)  )
x_vars = c()
i = 1
for (a1 in regressor_list) {
for (a2 in dep_list) {
tmp_formula_str = paste0(a2, ' ~ ', a1)
commandline = paste0('use_labels(data2work, glm(formula(', tmp_formula_str, '), family = binomial(link = "probit"), data = data2work ) )' )
tmp_model = eval(parse(text = commandline))
# cov1         = vcovHC(tmp_model, type = "HC1") # Never do robust errors for non linear model. Sometimes they are not even consistent.
# robust_se[[i]] = sqrt(diag(cov1))
reg_list[[i]] = tmp_model
x_vars = c(x_vars, a2)
i = i + 1
}
}
res = remove_backticks(
stargazer(
reg_list,
title="Results",
align=TRUE,
omit.stat = c("f"),
dep.var.caption  =  paste0("Dependent variable: ", eval(parse(text = paste0('var_lab(data2work$',dep_list[1],')'))) ),
dep.var.labels.include = FALSE,
df = FALSE,
digits = 5,
# notes        = TeX("Sometimes you just have to start over."),
# notes.append = FALSE,
se = robust_se))
# res[grepl("Note",res)] = note.latex
res[grepl("\\label\\{\\}",res)] = "%"
res[grepl("\\caption\\{",res)] = "%"
res[grepl("Table created by stargazer v.5.2.2 by Marek Hlavac",res)] = ""
res[grepl("\\% Date and time:",res)] = ""
res[grepl("\\% Requires LaTeX packages: dcolumn",res)] = ""
regmatches(res, gregexpr("(-?)(\\d+(,\\d+)?(\\.\\d+)?)", res)) =  lapply(regmatches(res, gregexpr("(-?)(\\d+(,\\d+)?(\\.\\d+)?)", res) ) , mysignif )
#
res[grepl("begin\\{table\\}",res)] = begintable.latex
res[grepl("end\\{table\\}",res)] = endtable.latex
cat("\014")
write_clip(res)
writeLines(res)
cat("\014")
writeLines(res)
cat("\014")
tmp_model = glm( critical_flag ~ tdiff50_recv1 + Repo_balances1 + coupon_issuances + QuarterEnd, family = binomial(link = "probit"), data = data2work )
tem1 = sd(data2work$tdiff50_recv1, na.rm=TRUE)
tem2 = sd(data2work$Repo_balances1, na.rm=TRUE)
# tem3 = sd(data2work$coupon_issuances, na.rm=TRUE)
tem3 = mean(data2work$coupon_issuances[data2work$coupon_issuances > 0.01], method = 'mfv', na.rm=TRUE)
tem4 = mean(data2work$tdiff50_recv1, na.rm=TRUE)
tem5 = mean(data2work$Repo_balances1, na.rm=TRUE)
tem6 = mean(data2work$coupon_issuances, na.rm=TRUE)
data2work_new = tibble(
tdiff50_recv1	    =	c(	tem4	,	tem4+tem1	,	 tem4	    ,  tem4+tem1, tem4+tem1  ,   	 tem4	   ,  	 tem4+tem1 ,	tem4	,	tem4+tem1	,	 tem4	     ,	 tem4	),
Repo_balances1	    =	c(	tem5	,	tem5	    ,	 tem5-tem2	,  tem5-tem2, tem5-tem2  ,   	 tem5	   ,  	 tem5-tem2 ,	tem5	,	tem5	    ,	 tem5-tem2	 ,	 tem5	),
coupon_issuances	=	c(	tem6	,	tem6	    ,	 tem6	    ,  tem6	    , tem6+tem3	 ,   	 tem6+tem3 ,  	 tem6+tem3 ,	tem6	,	tem6	    ,	 tem6	     ,	 tem6+tem3	),
QuarterEnd 	        =	c(	0	    ,	0	        ,	0	        ,   0	    ,  0	     ,   	0	       ,  	0	       ,	1	    ,	1	        ,	1	         ,	1	)
# tdiff50_recv1	=	c(	tem4	,	tem4+tem1	),
# Repo_balances1	=	c(	tem5	,	 tem5+tem2	),
# coupon_issuances	=	c(	 tem6	,	 tem6+tem3	),
# QuarterEnd 	=	c(	0	,	1	)
)
result = predict(tmp_model, type = "response", newdata = data2work_new, se.fit = TRUE)
data2work_new$prediction = as.numeric(result$fit)
data2work_new$se = as.numeric(result$se.fit)
data2work_new %<>% select(prediction, se, tdiff50_recv1, Repo_balances1, coupon_issuances,  QuarterEnd ) %>%
mutate(Repo_balances1 = Repo_balances1*1000, coupon_issuances = coupon_issuances*1000 )
res = stargazer(data2work_new, summary=FALSE, rownames=FALSE, digits = 4)
# Number inputs for Figure 5
regmatches(res, gregexpr("(-?)(\\d+(\\.\\d+)?)", res)) =  lapply(regmatches(res, gregexpr("(-?)(\\d+(\\.\\d+)?)", res) ) , mysignif )
write_clip(res)
writeLines(res)
library("ivreg")
library("AER")
regressor_list = c(
'Repo_balances1 + tdiff50_recv1 + QuarterEnd + Tbills_outstanding + total_redemptions_all + total_issuance_bills + coupon_issuances + DlrDepUnins + Corporation_Income_Taxes_trillion',
#
'Repo_balances1 + QuarterEnd + Tbills_outstanding  + total_redemptions_all +
total_issuance_bills + coupon_issuances + DlrDepUnins + Corporation_Income_Taxes_trillion | lag(p25Diff,n = 7) +
lag(p50Diff,n = 7) + lag(p75Diff,n = 7) + Tbills_outstanding + total_redemptions_all +
total_issuance_bills + coupon_issuances + QuarterEnd + DlrDepUnins + Corporation_Income_Taxes_trillion',
#
# #
'Repo_balances1 + tdiff50_recv1_residual + QuarterEnd + Tbills_outstanding  + total_redemptions_all +
total_issuance_bills + coupon_issuances + DlrDepUnins + Corporation_Income_Taxes_trillion | lag(p25Diff,n = 7) +
lag(p50Diff,n = 7) + lag(p75Diff,n = 7) + tdiff50_recv1_residual + Tbills_outstanding + total_redemptions_all +
total_issuance_bills + coupon_issuances + QuarterEnd + DlrDepUnins + Corporation_Income_Taxes_trillion'
# #
)
dep_list = c('SOFR_IOER')
reg_list = vector(mode = 'list', length = length(regressor_list) * length(dep_list) )
robust_se = vector(mode = 'list', length = length(regressor_list) * length(dep_list)  )
x_vars = c()
library("ivreg")
regressor_list = c(
'Repo_balances1 + tdiff50_recv1 + QuarterEnd + Tbills_outstanding + total_redemptions_all + total_issuance_bills + coupon_issuances + DlrDepUnins + Corporation_Income_Taxes_trillion',
#
'Repo_balances1 + QuarterEnd + Tbills_outstanding  + total_redemptions_all +
total_issuance_bills + coupon_issuances + DlrDepUnins + Corporation_Income_Taxes_trillion | lag(p25Diff,n = 7) +
lag(p50Diff,n = 7) + lag(p75Diff,n = 7) + Tbills_outstanding + total_redemptions_all +
total_issuance_bills + coupon_issuances + QuarterEnd + DlrDepUnins + Corporation_Income_Taxes_trillion',
#
# #
'Repo_balances1 + tdiff50_recv1_residual + QuarterEnd + Tbills_outstanding  + total_redemptions_all +
total_issuance_bills + coupon_issuances + DlrDepUnins + Corporation_Income_Taxes_trillion | lag(p25Diff,n = 7) +
lag(p50Diff,n = 7) + lag(p75Diff,n = 7) + tdiff50_recv1_residual + Tbills_outstanding + total_redemptions_all +
total_issuance_bills + coupon_issuances + QuarterEnd + DlrDepUnins + Corporation_Income_Taxes_trillion'
# #
)
dep_list = c('SOFR_IOER')
reg_list = vector(mode = 'list', length = length(regressor_list) * length(dep_list) )
robust_se = vector(mode = 'list', length = length(regressor_list) * length(dep_list)  )
x_vars = c()
i = 1
for (a1 in regressor_list) {
for (a2 in dep_list) {
tmp_formula_str = paste0(a2, ' ~ ', a1)
commandline = paste0('use_labels(data2work7, ivreg(formula(', tmp_formula_str, '), data = data2work7 ) )' )
tmp_model = eval(parse(text = commandline))
cov1         = vcovHC(tmp_model, type = "HC1")
robust_se[[i]] = sqrt(diag(cov1))
reg_list[[i]] = tmp_model
x_vars = c(x_vars, a2)
i = i + 1
}
}
rm( list = setdiff( ls(), c(keepVariables, "") ))
cat("\014")
data2work = data2work1
# ------------Stage 1 regression---------------------------------------------------------------------------------------------------------------------------------------------
# Table 13
model = use_labels(data2work,
lm(Repo_balances1 ~ lag(p25Diff,n = 7) + lag(p50Diff,n = 7) + lag(p75Diff,n = 7) +
Tbills_outstanding + total_redemptions_all +
total_issuance_bills + coupon_issuances + QuarterEnd + DlrDepUnins + Corporation_Income_Taxes_trillion,
na.action=na.exclude,
data = data2work ) )
model.1 = use_labels(data2work,
lm(
tdiff50_recv1 ~ lag(Repo_balances1),
# Repo_balances1 ~ lag(tdiff50_recv1),
na.action=na.exclude,
data = data2work ) )
model.2 = use_labels(data2work,
lm(
# tdiff50_recv1 ~ lag(Repo_balances1),
Repo_balances1 ~ lag(tdiff50_recv1),
na.action=na.exclude,
data = data2work ) )
tem = data2work
tem$Repo_balance_hat = fitted(model)
tem$Repo_balance_residual = residuals(model.2)
tem$tdiff50_recv1_residual = residuals(model.1)
tem %<>% select(Date, Repo_balance_hat, Repo_balance_residual, tdiff50_recv1_residual)
data2work7 = left_join(data2work, tem, by = "Date")
data2work7 =
apply_labels(
data2work7,
Repo_balance_hat = "predicted dealer opening balances",
Repo_balance_residual = "residual of dealer opening balances on lag median receive time from all banks",
tdiff50_recv1_residual = "residual of median receive time on opening balances"
)
rm( tem )
res = remove_backticks(
stargazer(
model,
title="Results",
align=TRUE,
# omit.stat = c("f"),
dep.var.caption  =  paste0("Dependent variable: ", eval(parse(text = paste0('var_lab(data2work$', 'Repo_balances1',')'))) ),
dep.var.labels.include = FALSE,
df = FALSE,
digits = 5
))
res[grepl("\\label\\{\\}",res)] = "%"
res[grepl("\\caption\\{",res)] = "%"
res[grepl("Table created by stargazer v.",res)] = ""
res[grepl("\\% Date and time:",res)] = ""
res[grepl("\\% Requires LaTeX packages: dcolumn",res)] = ""
regmatches(res, gregexpr("(-?)(\\d+(\\,\\d+)?(\\.\\d+)?)", res)) =  lapply(regmatches(res, gregexpr("(-?)(\\d+(\\,\\d+)?(\\.\\d+)?)", res) ) , mysignif )
res[grepl("begin\\{table\\}",res)] = begintable.latex
res[grepl("end\\{table\\}",res)] = endtable.latex
cat("\014")
write_clip(res)
writeLines(res)
cat("\014")
library("ivreg")
regressor_list = c(
'Repo_balances1 + tdiff50_recv1 + QuarterEnd + Tbills_outstanding + total_redemptions_all + total_issuance_bills + coupon_issuances + DlrDepUnins + Corporation_Income_Taxes_trillion',
#
'Repo_balances1 + QuarterEnd + Tbills_outstanding  + total_redemptions_all +
total_issuance_bills + coupon_issuances + DlrDepUnins + Corporation_Income_Taxes_trillion | lag(p25Diff,n = 7) +
lag(p50Diff,n = 7) + lag(p75Diff,n = 7) + Tbills_outstanding + total_redemptions_all +
total_issuance_bills + coupon_issuances + QuarterEnd + DlrDepUnins + Corporation_Income_Taxes_trillion',
#
# #
'Repo_balances1 + tdiff50_recv1_residual + QuarterEnd + Tbills_outstanding  + total_redemptions_all +
total_issuance_bills + coupon_issuances + DlrDepUnins + Corporation_Income_Taxes_trillion | lag(p25Diff,n = 7) +
lag(p50Diff,n = 7) + lag(p75Diff,n = 7) + tdiff50_recv1_residual + Tbills_outstanding + total_redemptions_all +
total_issuance_bills + coupon_issuances + QuarterEnd + DlrDepUnins + Corporation_Income_Taxes_trillion'
# #
)
dep_list = c('SOFR_IOER')
reg_list = vector(mode = 'list', length = length(regressor_list) * length(dep_list) )
robust_se = vector(mode = 'list', length = length(regressor_list) * length(dep_list)  )
x_vars = c()
i = 1
for (a1 in regressor_list) {
for (a2 in dep_list) {
tmp_formula_str = paste0(a2, ' ~ ', a1)
commandline = paste0('use_labels(data2work7, ivreg(formula(', tmp_formula_str, '), data = data2work7 ) )' )
tmp_model = eval(parse(text = commandline))
cov1         = vcovHC(tmp_model, type = "HC1")
robust_se[[i]] = sqrt(diag(cov1))
reg_list[[i]] = tmp_model
x_vars = c(x_vars, a2)
i = i + 1
}
}
note.latex = paste0(
"\\multicolumn{",
length(reg_list)+1,
"}{l}{{Note:} Standard errors are adjusted for heteroskedasticity. $^{*}p<0.1$; $^{**}p<0.05$; $^{***}p<0.01$.} \\\\ \\multicolumn{",
length(reg_list)+1,
"}{l}{ \\qquad \\quad Constant included for each specification.}")
res = remove_backticks(
stargazer(
reg_list,
title="Results",
align=TRUE,
omit.stat = c("f"),
dep.var.caption  =  paste0("Dependent variable: ", eval(parse(text = paste0('var_lab(data2work$',dep_list[1],')'))) ),
dep.var.labels.include = FALSE,
df = FALSE,
digits = 5,
# notes        = TeX("Sometimes you just have to start over."),
# notes.append = FALSE,
se = robust_se
))
res[grepl("Note",res)] = note.latex
res[grepl("\\label\\{\\}",res)] = "%"
res[grepl("\\caption\\{",res)] = "%"
res[grepl("Table created by stargazer v.",res)] = ""
res[grepl("\\% Date and time:",res)] = ""
res[grepl("\\% Requires LaTeX packages: dcolumn",res)] = ""
regmatches(res, gregexpr("(-?)(\\d+(\\,\\d+)?(\\.\\d+)?)", res)) =  lapply(regmatches(res, gregexpr("(-?)(\\d+(\\,\\d+)?(\\.\\d+)?)", res) ) , mysignif )
res[grepl("begin\\{table\\}",res)] = begintable.latex
res[grepl("end\\{table\\}",res)] = endtable.latex
cat("\014")
write_clip(res)
writeLines(res)
